﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mocking;
using Moq;
using Ploeh.AutoFixture;

namespace MSTestExamples
{
	/// <summary>
	/// Summary description for UnitTest1
	/// </summary>
	[TestClass]
	public class UnitTest1
	{
		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		[TestMethod]
		public void TestMethod9()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());				
			var c = fixture.CreateAnonymous<MyController>();
			Assert.IsNotNull(c.ShouldBeSet);
		}


		[TestMethod]
		public void TestMethod8()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());
			var c = fixture.CreateAnonymous<MyController>();
		}

		[TestMethod]
		public void TestMethod7()
		{
			var fixture = new Fixture();
			var r = fixture.CreateAnonymous<HttpResponseBase>();
		}

		[TestMethod]
		public void TestMethod6()
		{
			var fixture = new Fixture();
			var eda = fixture.CreateAnonymous<ExtensionDataObject>();
		}


		[TestMethod]
		public void TestMethod5()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());
			var sut = fixture.CreateAnonymous<ServiceBase>();

			var mock = fixture.MockOf<ICanTF>();
			mock.SetupGet(m => m.Is)
				.Returns(true);

			Assert.IsTrue(mock.Object.Is);
			Assert.IsTrue(sut.Can());

		}

		[TestMethod]
		public void TestMethod4()
		{
			var mock = new Mock<ICanTF>();
			mock.SetupGet(m => m.Is)
				.Returns(true);

			Assert.IsTrue(mock.Object.Is);
		}


		[TestMethod]
		public void TestMethod3()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());

			var sut = fixture.CreateAnonymous<UrlHelper>();
		}


		[TestMethod]
		public void TestMethod1()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());
			var sut = fixture.CreateAnonymous<CustomerService>();

			var account = fixture.Build<Account>()
				.Do(a => { a.IsActive = true; })
				.CreateAnonymous();

			var repositoryMock = fixture.MockOf<IRepository<Account>>();
			repositoryMock
				.Setup(rep => rep.Save(It.IsAny<Account>()))
				.Verifiable();

			sut.CloseAccount(account);

			repositoryMock.Verify();
		}

		[TestMethod]
		public void TestMethod2()
		{
			var fixture = new Fixture().Customize(new AutomockingCustomization());
			var sut = fixture.CreateAnonymous<AccountController>();

			var result = sut.Index();
			Assert.IsNotNull(result);
		}

		public object ExtensionDataObject { get; set; }
	}

	public interface ICanTF
	{
		bool Is { get; }
	}

	public class ServiceBase
	{
		ICanTF CanIf;
		public ServiceBase(ICanTF ictf)
		{
			CanIf = ictf;
		}

		public bool Can()
		{
			return CanIf.Is;
		}
	}
}
